
import { clone, lStorage } from '@/assets/utils'
import * as TYPES from '../action-type'

import api from '@/api'


let initialState = {
    loginInfo: null
}
// 个人登录信息 
export default function loginReducer(initial = initialState, action) {
    let state = clone(initial)
    let id = lStorage.getItem('userInfo')
    if (id?.id) {
        state.loginInfo = lStorage.getItem('userInfo');
    }
    switch (action.type) {
        case TYPES.LOGIN_POST || TYPES.REGISTER_POST :
            state.loginInfo = action.data;
            lStorage.setItem('userInfo', action.data)
            break;
            case TYPES.CLEAR_USERINFO   : // 清除登陆
                state.loginInfo =  null;
                lStorage.clear( )
                break    
    }

    return state
}